package windows;

import static org.junit.Assert.*;

import java.util.Set;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SwitchWindows {

	@Test
	public void switchWindows() {
		
		WebDriver driver = new FirefoxDriver();
		driver.get("http://compendiumdev.co.uk/selenium/frames/index.html");
		String origHandle = driver.getWindowHandle();
		driver.switchTo().frame("content");
		String evilWindowName = "evil";
		WebElement dev = driver.findElement(By.cssSelector("a[target='compdev']"));
		WebElement evil = driver.findElement(By.cssSelector("#goevil"));
		String devWindowName = dev.getAttribute("target");
		dev.click();
		evil.click();
		
		driver.switchTo().window(origHandle);
		driver.close();
		driver.switchTo().window(devWindowName);
		driver.close();
		driver.switchTo().window(evilWindowName);
		driver.quit();

		//driver.quit();
		
		/*Set<String> myHandles = driver.getWindowHandles();

		for(String s:myHandles){
			driver.switchTo().window(s);
			
			driver.close();
		}
		driver.quit();*/
	}	
	}